package empox.pos.operator;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

public class LoginAdapter 
extends BaseAdapter{
	Context con;
	OperatorInfo[] oi;
	boolean[] b;
	
	public LoginAdapter(Context context) {
		con = context;
	}
	
	public boolean[] setValue(OperatorInfo[] operatorinfo)
	{
		oi = operatorinfo;
		
		if(oi != null)
		{
			b = new boolean[oi.length];
			for( int i = 0 ; i < b.length ; i++)
				b[i] = false;
		
			b[0] = true;
			return b;
		}else
		{
			return null;
		}
	}
	
	public void setValue(boolean[] bl)
	{
		b = bl;
	}
	
	public int getCount() {
		if(oi != null)
			return oi.length;
		else
			return 0;
	}

	public Object getItem(int arg0) {
		return arg0;
	}

	public long getItemId(int arg0) {
		return arg0;
	}

	static class  SHOW
	{
		CheckBox cb;
		TextView tv;
	}
	
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		SHOW sh;
		if(arg1 == null)
		{
			sh = new SHOW();
			arg1 = new LinearLayout(con);
			
			sh.cb = new CheckBox(con);
			sh.cb.setFocusable(false);
			sh.cb.setEnabled(false);
			sh.cb.setWidth(50);
			((LinearLayout) arg1).addView(sh.cb);
			
			sh.tv = new TextView(con);
			sh.tv.setWidth(100);
			sh.tv.setGravity(Gravity.CENTER);
			((LinearLayout)arg1).addView(sh.tv);
			arg1.setTag(sh);
		}else
		{
			sh = (SHOW)arg1.getTag();
		}
		
		
		sh.cb.setChecked(b[arg0]);
		sh.tv.setText(oi[arg0].userName);
		
		return arg1;
	}
}
